/* eslint-disable */
import assetStateEchartsOption from './AssetStateEchartsOption'
import { getAction } from "@/api/manage";
import assetTypeEchartsOption from './AssetTypeEchartsOption'
import YearSelect from '@/components/YearSelect'
import assetInStooreEchartsOption from './AssetInStoreEchartsOption'

export default {
  components: { YearSelect },
  data() {
    return {
      url: {
        state : "/dashboard/state",
        classify:"/dashboard/classify",
        instore:"/dashboard/instore",
        upcomingList:"/dashboard/upcomingList"
      },
      messaeList:[],
      inStoreYear:null,
    }
  },
  mounted() {
    this.expiration()
    this.$nextTick(function () {
      this.drawChart()
      this.upcoming();
    })
  },
  methods: {
    goRouter(path){
      this.$router.push(path);
    },
    // 领用到期资产提醒
    expiration() {
      // this.$notify.error({
      //   title: '领用到期资产提醒',
      //   message: '领用到期资产提醒：XXX资产于3日后到期，请关注！',
      //   duration: 0
      // })
    },
    //待办事项
    upcoming(){
      let that = this;
      getAction(this.url.upcomingList).then(res => {
        if(res.success){
          //入库审批
          if(res.data.instoreCount>0){
            that.messaeList.push({text:` 您有[${res.data.instoreCount}]条入库信息需要审核，请及时处理！`,path:'/assetBusiness/review' ,icon:'el-icon-info' })
          }
          //盘点
          if(res.data.inventoryCount>0){
            that.messaeList.push({text:` 您有[${res.data.inventoryCount}]条盘点单正在盘点，请及时处理！`,path:'/queryDisplay/inventory',icon:'el-icon-info'})
          }
          //处置
          if(res.data.disposeCount>0){
             that.messaeList.push({text:` 您有[${res.data.dueCount}]条资产即将到期需要处置，请及时处理！`,path:'/assetBusiness/disposal',icon:'el-icon-message-solid'})
          }
          //归还
          if(res.data.dueCount>0){
            that.messaeList.push({text:` 您有[${res.data.dueCount}]条资产即将需要归还，请及时处理！`,path:'/assetBusiness/returnAsset',icon:'el-icon-message-solid'})
          }
        }
      });
    },
    // 绘制图表
    drawChart(){
      this.assetStateChart();
      this.assetTypeChart();
      this.assetInstoreEchartsOption();
    },
    onInstoreYear(val){
      this.assetInstoreEchartsOption();
    },
    assetInstoreEchartsOption(){
      let myChart = this.$echarts.init(document.getElementById('assetInstore'))
      myChart.showLoading();
      myChart.setOption(assetInStooreEchartsOption());
      getAction(this.url.instore+"/"+this.inStoreYear).then(res => {
        if(res.success){
          let currData = res.data.curr;
          let preData = res.data.pre;
          myChart.setOption({
            legend: {
              data: [this.inStoreYear-1+'', this.inStoreYear+'']
            },
            series: [
              {
                name: this.inStoreYear-1,
                type: 'bar',
                data: [preData[1],preData[2],preData[3],preData[4],preData[5],preData[6],preData[7],
                  preData[8],preData[9],preData[10],preData[11],preData[12],]
              },
              {
                name: this.inStoreYear,
                type: 'bar',
                data: [currData[1],currData[2],currData[3],currData[4],currData[5],currData[6],currData[7],
                  currData[8],currData[9],currData[10],currData[11],currData[12],]
              },
            ]
          });
        }
        myChart.hideLoading();
      });
    },
    assetStateChart(){
      let myChart = this.$echarts.init(document.getElementById('assetState'))
      myChart.showLoading();
      myChart.setOption(assetStateEchartsOption());
      getAction(this.url.state).then(res => {
        if(res.success){
          let  data = res.data.map(dataMap =>  {
            return {
              value:dataMap.count,
              name:['闲置','已领用','已处置'][dataMap.groupBy - 1]
            }
          });

          myChart.setOption({
            legend: {
              left: 'center',
              top: 'bottom',
              data: data.map(temp => temp.name)
            },
            series: [
              {
                name: '资产状态', type: 'pie',
                radius: [30, 110],
                center: ['50%', '50%'],
                data:data,
                emphasis: {
                  itemStyle: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                  }
                }
              }
            ]
          });
        }
        myChart.hideLoading();
      });
    },
    assetTypeChart(){
      let myChart = this.$echarts.init(document.getElementById('assetType'))
      myChart.showLoading();
      myChart.setOption(assetTypeEchartsOption());
      getAction(this.url.classify).then(res => {
        if(res.success){
          let classeseData = res.data.classes.map(dataMap =>  {
            return {
              value:dataMap.count,
              name:['土地','房屋及构筑物','通用设备','车辆','专用设备','文物及陈列品','图书档案','家具用具及装具'][dataMap.groupBy - 1]
            }
          });
          let typeData = res.data.type.map(dataMap =>  {
            return {
              value:dataMap.count,
              name:dataMap.groupBy
            }
          });
          myChart.setOption({
            legend: {
              type: 'scroll',
              left: 'center',
              top: 'bottom',
              data: classeseData.map(temp => temp.name).concat(typeData.map(temp => temp.name))
            },
            series: [
              {
                name: '资产大类',
                type: 'pie',
                selectedMode: 'single',
                radius: [0, '40%'],
                label: {
                  position: 'inner'
                },
                labelLine: {
                  show: false
                },
                data:classeseData,
                emphasis: {
                  itemStyle: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                  }
                }
              },
              {
                name: '资产分类',
                type: 'pie',
                radius: ['55%', '70%'],
                label: {
                  formatter: '{a|{a}}{abg|}\n{hr|}\n  {b|{b}：}{c}  {per|{d}%}  ',
                  backgroundColor: '#eee',
                  borderColor: '#aaa',
                  borderWidth: 1,
                  borderRadius: 4,
                  rich: {
                    a: {
                      color: '#999',
                      lineHeight: 22,
                      align: 'center'
                    },
                    hr: {
                      borderColor: '#aaa',
                      width: '100%',
                      borderWidth: 0.5,
                      height: 0
                    },
                    b: {
                      fontSize: 12,
                      lineHeight: 23
                    },
                    per: {
                      color: '#eee',
                      backgroundColor: '#334455',
                      padding: [2, 2],
                      borderRadius: 2
                    }
                  }
                },
                data: typeData
              }]
          });
        }
        myChart.hideLoading();
      });
    }
  }
}
